<?php
/*
 * Name:      Master data
 * Directory: Master data
 * Version:   1.0.0
 * Type:      user
 * UI Name:   Master data
 * UI Icon:
 */

// MODULE CONFIGURATION DEFINITION
$config = array();
$config['mod_name'] = 'masterdata';		// name the module
$config['mod_version'] = '1.0.0';		// add a version number
$config['mod_directory'] = 'masterdata';		// tell dotProject where to find this module
$config['mod_setup_class'] = 'CSetupMasterdata';	// the name of the PHP setup class (used below)
$config['mod_type'] = 'user';			// 'core' for modules distributed with dP by standard, 'user' for additional modules from dotmods
$config['mod_ui_name'] = 'Master data';		// the name that is shown in the main menu of the User Interface
$config['mod_ui_icon'] = 'masterdata48x48.png';	// name of a related icon
$config['mod_description'] = 'Showing a random quote from Albert Einstein';	// some description of the module
$config['mod_config'] = true;			// show 'configure' link in viewmods

// show module configuration with the dPframework (if requested via http)
if (@$a == 'setup') {
	echo dPshowModuleConfig( $config );
}

class CSetupMasterdata {

	function configure() {		// configure this module
	global $AppUI;
		$AppUI->redirect( 'm=masterdata&a=configure' );	// load module specific configuration page
  		return true;
	}

	function remove() {		// run this method on uninstall process
	/*
		db_exec( "DROP TABLE md_status;" );	// remove the einstein table from database
		db_exec( "DROP TABLE md_type;" );	// remove the einstein table from database
		db_exec( "DROP TABLE md_item;" );	// remove the einstein table from database
		db_exec( "DROP TABLE md_currency;" );	// remove the md_currency table from database
		db_exec( "DROP TABLE md_unit;" );	// remove the md_unit table from database
		db_exec( "DROP TABLE md_jobtitle;" );	// remove the md_jobtitle table from database
		db_error();
	*/
		return null;
	}


	function install() {
		
		$sql = "CREATE TABLE `md_status` (
			  `status_id` int(11) unsigned NOT NULL auto_increment,
			  `status_code` varchar(255) NOT NULL,
			  `status_name` varchar(255) NOT NULL,
			  `status_type` varchar(255) NOT NULL,
			  `status_active` int(4) default NULL,
			  PRIMARY KEY  (`status_id`),
			  UNIQUE KEY `status_id` (`status_code`)
			) ENGINE=MyISAM;";

		db_exec( $sql ); db_error();						// execute the queryString

		$sql = "CREATE TABLE `md_type` (
			  `type_id` int(11) unsigned NOT NULL auto_increment,
			  `code` varchar(255) NOT NULL,
			  `name` varchar(255) NOT NULL,
			  `type` varchar(255) NOT NULL,
			  `active` int(4) default NULL,
			  PRIMARY KEY  (`type_id`),
			  UNIQUE KEY `type_id` (`code`)
			) ENGINE=MyISAM  ;";

		db_exec( $sql ); db_error();

		$sql = "CREATE TABLE md_item ( " .					// prepare the creation of a dbTable
			"  item_id int(11) unsigned NOT NULL auto_increment" .
			", category varchar(255) NOT NULL" .
			", code varchar(255) NOT NULL" .
			", name varchar(255) NOT NULL " .
			", type int(11)" .
			", status int(11)" .
			", active int(4)" .
			", PRIMARY KEY  (item_id)" .
			", UNIQUE KEY item_id (code)" .
			") TYPE=MyISAM;";

		db_exec( $sql ); db_error();						// execute the queryString
		// trangdt
		//currency
		$sql = "CREATE TABLE md_currency ( " .					// prepare the creation of a dbTable
			"  currency_id int(11) unsigned NOT NULL auto_increment" .
			", currency_code varchar(3) NOT NULL" .
			", currency_name varchar(150) NOT NULL " .
			", currency_abbreviation varchar(3) NOT NULL" .
			", currency_active int(4)" .
			", PRIMARY KEY  (currency_id)" .
			", UNIQUE KEY currency_id (currency_code)" .
			") TYPE=MyISAM;";

		db_exec( $sql ); db_error();						// execute the queryString
		// unit
		$sql = "CREATE TABLE md_unit ( " .					// prepare the creation of a dbTable
			"  unit_id int(11) unsigned NOT NULL auto_increment" .
			", unit_code varchar(20) NOT NULL" .
			", unit_name varchar(150) NOT NULL " .
			", unit_status int(11) NOT NULL" .
			", unit_type int(11) NOT NULL" .
			", unit_active int(4)" .
			", PRIMARY KEY  (unit_id)" .
			", UNIQUE KEY unit_id (unit_code)" .
			") TYPE=MyISAM;";

		db_exec( $sql ); db_error();						// execute the queryString
		//Job_Title
		$sql = "CREATE TABLE md_jobtitle ( " .					// prepare the creation of a dbTable
			"  jobtitle_id int(11) unsigned NOT NULL auto_increment" .
			", jobtitle_code varchar(20) NOT NULL" .
			", jobtitle_name varchar(150) NOT NULL " .
			", jobtitle_active int(4)" .
			", PRIMARY KEY  (jobtitle_id)" .
			", UNIQUE KEY jobtitle_id (jobtitle_code)" .
			") TYPE=MyISAM;";
		db_exec( $sql ); db_error();
		// devision
		$sql= "CREATE TABLE `divisions` (                   
             `div_id` int(11) NOT NULL auto_increment,  
             `div_code` varchar(255) NOT NULL,          
             `div_name` varchar(255) NOT NULL,          
             `div_address` varchar(255) default NULL,   
             `div_tel` varchar(255) default NULL,       
             `div_fax` varchar(255) default NULL,       
             PRIMARY KEY  (`div_id`)                    
           ) ENGINE=MyISAM ";
           db_exec( $sql ); db_error();
        // cost center
        $sql= "CREATE TABLE `costcenters` (                   
             `cc_id` int(11) NOT NULL auto_increment,  
             `cc_code` varchar(20) NOT NULL,          
             `cc_name` varchar(150) NOT NULL,          
             `cc_division` int(11) NOT NULL,   
             PRIMARY KEY  (`cc_id`)                    
           ) ENGINE=MyISAM ";
           db_exec( $sql ); db_error();
        // Classification
        $sql= "CREATE TABLE `classifications` (                   
             `cls_id` int(11) NOT NULL auto_increment,  
             `cls_code` varchar(20) NOT NULL,          
             `cls_name` varchar(150) NOT NULL,          
             `cls_type` int(4) NOT NULL,   
             PRIMARY KEY  (`cls_id`)                    
           ) ENGINE=MyISAM ";
           db_exec( $sql ); db_error();
		// end trangdt		
		return null;
	}

}

?>